package com.atguigu.tingshu.order.service.impl;

import com.atguigu.tingshu.model.order.LocalMsg;
import com.atguigu.tingshu.order.mapper.LocalMsgMapper;
import com.atguigu.tingshu.order.mapper.OrderInfoMapper;
import com.atguigu.tingshu.order.service.MqOpsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MqOpsServiceImpl implements MqOpsService {

    @Autowired
    private LocalMsgMapper localMsgMapper;

    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Override
    public void updateLocalMsgStatus(String content) {

        LambdaQueryWrapper<LocalMsg> localMsgLambdaQueryWrapper = new LambdaQueryWrapper<>();
        localMsgLambdaQueryWrapper.eq(LocalMsg::getMsgContent,content);
        LocalMsg localMsg = localMsgMapper.selectOne(localMsgLambdaQueryWrapper);
        if (localMsg != null){
            localMsg.setStatus(1);
            localMsgMapper.updateById(localMsg);
        }

    }

    @Override
    public void cancelOrder(String orderNo) {
        int count = orderInfoMapper.cancelOrder(orderNo);
        log.info("关闭订单：{}",count > 0 ? "success" : "fail");
    }

}
